﻿using Abp.Application.Features;
using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;
using Mt.Site.Core.Authorization;
using Mt.Site.Core.Base.Authorization;
using Mt.Site.Core.Messages_.Features;

namespace Mt.Site.Core.Messages_.Permissions
{
    public class MessagesPermissionProvider : AuthorizationProvider
    {
        public const string ModuleName = "App.Module.Messages";
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            var messagesFeature = new SimpleFeatureDependency(true, MessagesFeatures.MessagesFeature);

            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));
            var MessagesManage = pages.CreateChildMtMenuPermission(
                MessagesPermissions.Pages_Manage_Messages,
                ModuleName,
                false, L("Messages"), multiTenancySides: MultiTenancySides.Tenant);
            MessagesManage.CreateChildMtMenuPermission(
                MessagesPermissions.Pages_Manage_Messages_Create,
                ModuleName,
                false, L("CreateMessages"), multiTenancySides: MultiTenancySides.Tenant);
            MessagesManage.CreateChildMtMenuPermission(MessagesPermissions.Pages_Manage_Messages_Update,
                ModuleName,
                false, L("UpdateMessages"), multiTenancySides: MultiTenancySides.Tenant);
            MessagesManage.CreateChildMtMenuPermission(MessagesPermissions.Pages_Manage_Messages_Delete,
                ModuleName,
                false, L("DeleteMessages"), multiTenancySides: MultiTenancySides.Tenant);
            MessagesManage.CreateChildMtMenuPermission(MessagesPermissions.Pages_Manage_Messages_Query,
                ModuleName,
                false, L("QueryMessages"), multiTenancySides: MultiTenancySides.Tenant);
            MessagesManage.CreateChildMtMenuPermission(MessagesPermissions.Pages_Manage_Messages_ExportOut,
                ModuleName,
                false, L("ExportOutMember"), multiTenancySides: MultiTenancySides.Tenant);

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, MtSiteConsts.LocalizationSourceName_Permissions);
        }
    }
}
